<?php

Raise::load('core.exception.RaiseRuntimeException');

/**
 * RaiseDatabaseException Exception Class
 * An exception that indicates that a database SQL query / update exception has occurred.
 *
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package phpraise.exception
 * @since 1.2
 */
class RaiseDatabaseSQLException extends RaiseRuntimeException {

    /**
     * The internal error describing this SQL exception
     * @var string
     */
    private $internalError;
    
    /**
     * The query string with relations to this error
     * @var string
     */
    private $query;

    /**
     * Creates a new Exception
     * @param string $message The message of the exception
     */
    public function __construct($message, $query, $internalError) {
        parent::__construct($message, '30021', null);
        $this->query = $query;
        $this->internalError = $internalError;
    }

    /**
     * Get or set the internal error describing this SQL exception
     * @param string $i (optional) Set the internal error describing this SQL exception
     * @return string
     */
    public function internalError($i = null){
        if(func_num_args() == 1){
            $this->internalError = $i;
        }
        return $this->internalError;
    }

    /**
     * Get or set the query string with relations to this error
     * @param string $q (optional) Set the query string with relations to this error
     * @return string
     */
    public function query($q = null){
        if(func_num_args() == 1){
            $this->query = $q;
        }
        return $this->query;
    }
}
